﻿Imports BUS
Imports DTO
Imports System.Data.SqlClient
Public Class frmMain

    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Public Shared user As String

    Shared Property ten As Integer

    Private Sub ĐăngNhậpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐăngNhậpToolStripMenuItem.Click
        frmDangNhap.Show()
        Me.Hide()

    End Sub

    Private Sub PhiếuXuấtKhoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub ThoátToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThoátToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub ThoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThoToolStripMenuItem.Click
        frmTHONGTINKHACHHANG.Show()
    End Sub

    Private Sub HoaDonMuaHangToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HoaDonMuaHangToolStripMenuItem.Click
        frmHOADON.Show()
    End Sub

    Private Sub BáoCáoDoanhThuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoDoanhThuToolStripMenuItem.Click
        frmBAOCAODOANHTHU.Show()
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        frmAbout.Show()
    End Sub

    Private Sub ThôngTinSảnPhẩmToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThôngTinSảnPhẩmToolStripMenuItem1.Click
        frmTHEMSANPHAM.Show()
    End Sub

    Private Sub NhàCungCấpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NhàCungCấpToolStripMenuItem.Click
        frmThemNCC.Show()
    End Sub

    Private Sub KháchHàngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KháchHàngToolStripMenuItem.Click
        frmTHEMKHACHHANG.Show()
    End Sub

    Private Sub PhiếuXuấtKhoToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhiếuXuấtKhoToolStripMenuItem1.Click
        frmCHITIETPHIEUXUAT.Show()
    End Sub

    Private Sub ThôngTinSảnPhẩmToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThôngTinSảnPhẩmToolStripMenuItem.Click
        frmTHONGTINMATHANG.Show()
    End Sub

    Private Sub PhiếuNhậpKhoToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhiếuNhậpKhoToolStripMenuItem1.Click
        frmCHITIETPHIEUNHAP.Show()

    End Sub

    Private Sub BackupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupToolStripMenuItem.Click
        Dim dialog As New SaveFileDialog
        dialog.InitialDirectory = "D:\"
        dialog.Title = "Save Backup Files"
        dialog.CheckPathExists = True
        dialog.DefaultExt = "bak"
        dialog.Filter = "Backup files (*.bak)|*.bak|All files (*.*)|*.*"
        dialog.FilterIndex = 2
        dialog.RestoreDirectory = True
        If (dialog.ShowDialog() = DialogResult.OK) Then
            Dim cn As New BackUpBUS()
            cn.data()
            cn.backup(dialog.FileName)

        End If
        MessageBox.Show("Sao lưu dữ liệu thành công")
    End Sub
 

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con = New SqlConnection("Data Source=ThanhDuc\Admin;Integrated Security=SSPI;Initial Catalog=DBNGK")
        If ten = 0 Then
           
            Label2.Text = "Admin"
            Label5.Text = "Admin"
        ElseIf ten = 1 Then
            BackupToolStripMenuItem.Enabled = False
            RetoToolStripMenuItem.Enabled = False
            TàiKhoảnToolStripMenuItem.Enabled = False
            Label2.Text = "User"
            Label5.Text = "User"
        End If
    End Sub

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub NhanVienToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NhanVienToolStripMenuItem.Click
        frmTHEMNHANVIEN.Show()
    End Sub

    Private Sub RetoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RetoToolStripMenuItem.Click
        Dim dialog As New OpenFileDialog()
        dialog.InitialDirectory = "D:\"
        dialog.Title = "Open Backup Files"
        dialog.CheckPathExists = True
        dialog.DefaultExt = "bak"
        dialog.Filter = "Backup files (*.bak)|*.bak|All files (*.*)|*.*"
        dialog.FilterIndex = 2
        dialog.RestoreDirectory = True
        If (dialog.ShowDialog() = DialogResult.OK) Then
            Dim cn As New BackUpBUS()
            cn.data()
            cn.Restore(dialog.FileName)
            MessageBox.Show("Dữ Liệu Đã Được Khôi Phục")

        End If
    End Sub
  

    Private Sub ĐăngXuấtToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐăngXuấtToolStripMenuItem.Click
        frmDangNhap.Show()
        Me.Close()
    End Sub

 

    Private Sub ImportToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    

    Private Sub ExportToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
   
    Private Sub XuấtHĐRaFileExcelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XuấtHĐRaFileExcelToolStripMenuItem.Click
        XuatFile()
    End Sub
    Public Sub XuatFile()
        Dim dialog As New SaveFileDialog
        dialog.InitialDirectory = "D:\"
        dialog.Title = "Save Excel Files"
        dialog.CheckPathExists = True
        dialog.DefaultExt = "xls"
        dialog.Filter = "Excel files (*.xls 1997 - 2003)|*.xls|Excel files (*.xls 2007-2013)|*.xlsx|All files (*.*)|*.*"
        dialog.FilterIndex = 2
        dialog.RestoreDirectory = True
        If (dialog.ShowDialog() = DialogResult.OK) Then
            ExpostToExell.Export(dialog.FileName)
            MessageBox.Show("Xuất dữ liệu ra file excel thành công", "SQL Authetication")

        End If
    End Sub

    Private Sub NhậpTừFileExcelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NhậpTừFileExcelToolStripMenuItem.Click
        NhapFile()
    End Sub
    Public Sub NhapFile()
        Dim dialog As New OpenFileDialog()
        dialog.InitialDirectory = "D:\"
        dialog.Title = "Open Excel Files"
        dialog.CheckPathExists = True
        dialog.DefaultExt = "xls"
        dialog.Filter = "Excel files (*.xls 1997 - 2003)|*.xls|Excel files (*.xls 2007-2013)|*.xlsx|All files (*.*)|*.*"
        dialog.FilterIndex = 2
        dialog.RestoreDirectory = True
        If (dialog.ShowDialog() = DialogResult.OK) Then
            ExpostToExell.Import(dialog.FileName)

        End If
    End Sub

    Private Sub HeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HeToolStripMenuItem.Click
        System.Diagnostics.Process.Start("Help.chm")
    End Sub

    Private Sub TàiKhoảnToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TàiKhoảnToolStripMenuItem.Click
        frmDangKi.Show()
        Me.Hide()
    End Sub
End Class
